define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'customers_contract/index' + location.search,
                    add_url: 'customers_contract/add',
                    edit_url: 'customers_contract/edit',
                    del_url: 'customers_contract/del',
                    multi_url: 'customers_contract/multi',
                    import_url: 'customers_contract/import',
                    table: 'user_customers_contract',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'customers_id', title: __('Customers_id')},
                        {field: 'created_by', title: __('Created_by'), operate: 'LIKE'},
                        {field: 'contract_type', title: __('Contract_type'), operate: 'LIKE'},
                        {field: 'course_category', title: __('Course_category'), operate: 'LIKE'},
                        {field: 'subcategory', title: __('Subcategory'), operate: 'LIKE'},
                        {field: 'contract_lessons', title: __('Contract_lessons')},
                        {field: 'contract_lenght', title: __('Contract_lenght'), operate: 'LIKE'},
                        {field: 'start_date', title: __('Start_date'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'end_date', title: __('End_date'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'contract_lessons_paid', title: __('Contract_lessons_paid')},
                        {field: 'contract_lessons_free', title: __('Contract_lessons_free')},
                        {field: 'other_office', title: __('Other_office'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'start_level', title: __('Start_level'), operate: 'LIKE'},
                        {field: 'end_level', title: __('End_level'), operate: 'LIKE'},
                        {field: 'cool_coin', title: __('Cool_coin'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'consultant', title: __('Consultant'), operate: 'LIKE'},
                        {field: 'in_charge_teacher', title: __('In_charge_teacher'), operate: 'LIKE'},
                        {field: 'teacher_kpi', title: __('Teacher_kpi'), operate: 'LIKE'},
                        {field: 'currency', title: __('Currency'), operate: 'LIKE'},
                        {field: 'contract_tuition', title: __('Contract_tuition'), operate:'BETWEEN'},
                        {field: 'schoolarship_amount', title: __('Schoolarship_amount'), operate:'BETWEEN'},
                        {field: 'contract_amount', title: __('Contract_amount'), operate:'BETWEEN'},
                        {field: 'book_fee', title: __('Book_fee'), operate:'BETWEEN'},
                        {field: 'enrollment_fee', title: __('Enrollment_fee'), operate:'BETWEEN'},
                        {field: 'other_fee', title: __('Other_fee'), operate:'BETWEEN'},
                        {field: 'status', title: __('Status'), searchList: {"255":__('Status 255')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
